﻿using System;
using UnityEngine;
using System.Collections;

public class FogOfWar : MonoBehaviour {
    private SpriteRenderer[] _renderers;
	public GameObject target;
	// Use this for initialization
	void Start () {
	    _renderers = GetComponentsInChildren<SpriteRenderer>();
		setAll (false);
	}

    public float FadeTime = 5;
    public void Show() {
		setAll (true);
        StopCoroutine("HideDelayed");
        StartCoroutine("HideDelayed");
    }

    IEnumerator HideDelayed() {
        yield return new WaitForSeconds(FadeTime);
        Hide(); 
    }
    private void Hide() {
		setAll (false);
    }

	private void setAll(bool state) {
		if(_renderers == null) return;
		foreach(var r in _renderers) {
				r.enabled = state;
		}
	}
	// Update is called once per frame
	void Update () {
	
	}
}
